<template>
    <div>
        <!--表格信息-->
        <el-table :data="empSals" border stripe>
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="name" label="姓名" fixed></el-table-column>
            <el-table-column prop="idCard" label="工号"></el-table-column>
            <el-table-column prop="email" label="邮箱地址"></el-table-column>
            <el-table-column prop="phone" label="电话号码"></el-table-column>
            <el-table-column prop="department.name" label="所属部门"></el-table-column>
            <el-table-column label="工资账套">
                <template slot-scope="scope">
                    <el-tooltip placement="right" v-if="scope.row.salary">
                        <div slot="content">
                            <!--工资账套信息悬浮展示内容-->
                            <table>
                                <tr>
                                    <td>基本工资</td>
                                    <td>{{scope.row.salary.basicSalary}}</td>
                                </tr>
                                <tr>
                                    <td>交通补助</td>
                                    <td>{{scope.row.salary.trafficSalary}}</td>
                                </tr>
                                <tr>
                                    <td>午餐补助</td>
                                    <td>{{scope.row.salary.lunchSalary}}</td>
                                </tr>
                                <tr>
                                    <td>奖金</td>
                                    <td>{{scope.row.salary.bonus}}</td>
                                </tr>
                                <tr>
                                    <td>养老金比率</td>
                                    <td>{{scope.row.salary.pensionPer}}</td>
                                </tr>
                                <tr>
                                    <td>养老金基数</td>
                                    <td>{{scope.row.salary.pensionBase}}</td>
                                </tr>
                                <tr>
                                    <td>医疗保险比率</td>
                                    <td>{{scope.row.salary.medicalPer}}</td>
                                </tr>
                                <tr>
                                    <td>医疗保险基数</td>
                                    <td>{{scope.row.salary.medicalBase}}</td>
                                </tr>
                                <tr>
                                    <td>公积金比率</td>
                                    <td>{{scope.row.salary.accumulationFundPer}}</td>
                                </tr>
                                <tr>
                                    <td>公积金基数</td>
                                    <td>{{scope.row.salary.accumulationFundBase}}</td>
                                </tr>


                            </table>
                        </div>
                        <el-tag>{{scope.row.salary.name}}</el-tag>
                    </el-tooltip>
                    <el-tag v-else>暂未设置</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-popover
                            placement="left"
                            @show="showPop(scope.row.salary)"
                            @hide="hidePop(scope.row)"
                            title="修改工资账套"
                            size="mini"
                            width="200"
                            trigger="click">
                        <div>
                            <el-select v-model="currentSalary" placeholder="请选择">
                                <el-option
                                        v-for="item in salaries"
                                        :key="item.id"
                                        :label="item.name"
                                        :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                        <el-button slot="reference" size="mini" type="danger">修改工资账套</el-button>
                    </el-popover>
                </template>
            </el-table-column>
        </el-table>
        <!--分页组件-->
        <div style="display: flex;justify-content: flex-end;margin-top: 5px">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-sizes="[10, 20, 30, 40,50]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: "SalSobCfg",
        data() {
            return {
                //表格数据
                empSals: [],
                current: 1,
                size: 10,
                total: 0,
                //全部工资账套
                salaries: [],
                //当前工资账套
                currentSalary: null,
            }
        },
        methods: {
            /**
             * 初始化表格数据，获取员工账套
             */
            initSalSob() {
                this.getRequest('/salary/sobcfg/getEmployeeSalary?currentPage=' + this.current + '&size=' + this.size).then(res => {
                    if (res) {
                        this.empSals = res.data;
                        this.total = res.total;
                    }
                })
            },
            /**
             * 改变当前页
             * @param currentPage
             */
            handleCurrentChange(current) {
                this.current = current;
                this.initSalSob();
            }
            ,
            /**
             * 改变一页显示的条数
             * @param size
             */
            handleSizeChange(size) {
                this.size = size;
                this.initSalSob();
            },
            /**
             * 初始化获取全部工资账套
             */
            initAllSalaries() {
                this.getRequest('/salary/sobcfg/getAllSalary').then(res => {
                    if (res) {
                        this.salaries = res;
                    }
                })
            },
            /**
             * 点击修改工资账套按钮，显示popover悬浮窗之前触发的事件
             * @param data
             */
            showPop(data) {
                if (data) {
                    this.currentSalary = data.id;
                } else {
                    this.currentSalary = null;
                }
            },
            /**
             * 关闭popover悬浮窗后触发的事件
             * @param data
             */
            hidePop(data) {

                if (this.currentSalary && this.currentSalary !== data.salary.id) {
                    this.putRequest('/salary/sobcfg/updateEmployeeSalary?eid=' + data.id + '&sid=' + this.currentSalary).then(res => {
                        if (res) {
                            this.initSalSob();
                        }
                    })
                }
            }
        },
        mounted() {
            this.initSalSob();
            this.initAllSalaries();
        }
    }
</script>

<style scoped>

</style>
